package com.example.dllo.exe.fenlei.xuanlishenqi;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.bean.XuanLiShenQiBean;
import com.example.dllo.exe.fengzhuang.NetTool;

/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class XuLiShenQiRVAdapter extends RecyclerView.Adapter<XuLiShenQiRVAdapter.MyViewHolder> {
    private Context context;
    private XuanLiShenQiBean xuanLiShenQiBean;

    public void setXuanLiShenQiBean(XuanLiShenQiBean xuanLiShenQiBean) {
        this.xuanLiShenQiBean = xuanLiShenQiBean;
        notifyDataSetChanged();
    }

    public XuLiShenQiRVAdapter(Context context) {
        this.context = context;
    }

    @Override
    public XuLiShenQiRVAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fenleixuanlishenqifragmentlayout, parent, false);
        MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(XuLiShenQiRVAdapter.MyViewHolder holder, int position) {
        NetTool netTool=new NetTool();
        netTool.getImage(xuanLiShenQiBean.getData().getItems().get(position).getCover_image_url(),holder.imageViewcoverimage);

        holder.textViewname.setText(xuanLiShenQiBean.getData().getItems().get(position).getName());
        holder.textViewprivace.setText(xuanLiShenQiBean.getData().getItems().get(position).getPrice());
        holder.likscounts.setText(xuanLiShenQiBean.getData().getItems().get(position).getLikes_count()+"");
    }

    @Override
    public int getItemCount() {
        return xuanLiShenQiBean!=null?xuanLiShenQiBean.getData().getItems().size():0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView imageViewcoverimage;
        TextView textViewname;
        TextView textViewprivace;
        TextView likscounts;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageViewcoverimage= (ImageView) itemView.findViewById(R.id.Image_fenei);
            textViewname= (TextView) itemView.findViewById(R.id.Name_fenlei);
            textViewprivace= (TextView) itemView.findViewById(R.id.Price_FenLei);
            likscounts= (TextView) itemView.findViewById(R.id.Favorites_FenLei);
        }
    }
}
